import count from '@feidao-factory/atom-nodejs/db/count';
import query from '@feidao-factory/atom-nodejs/db/query';
import { systemid } from './config';

interface Message {
	page_size: number;
	page_no: number;
	asc?: string[];
	desc?: string[];
	fliter: {
		assessment_items?: {},
		appraisal_type?: {}
	};
}

// assessment_items 考核项--数据表
interface Assessmentitems {
	_id: string;                              // id
	assessment_items: string;                  // 考核项目
	appraisal_type: string;                    // 考核类型
	assessment_classification: string;        // 考核分类
	proportion_assessment_items: string;      // 考核项所占比例
	contents_assessment_items: string;        // 考核项内容
	appraisal_item_number: string;            // 考核项编号
}

export default async function atom(msg: Message, action_id: string, session_id: string) {
	const { exec, prepare } = query(action_id, session_id, systemid);
	const c = count(action_id, session_id, systemid);

	prepare('assessment_items', ['assessment_items', 'appraisal_type', 'assessment_classification', 'proportion_assessment_items', 'contents_assessment_items', 'appraisal_item_number'], msg.fliter, msg.page_size, msg.page_no, msg.asc, msg.desc);
	const [data] = await exec<Assessmentitems>();
	c.prepare('assessment_items', msg.fliter);
	const [t] = await c.exec();
	return { dataArray: data, count: t, page_size: msg.page_size, page_no: msg.page_no };
}
